package com.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo.dao.UserDao;
import com.demo.model.User;
import com.demo.service.IUserService;

/**
 * 用户业务处理实现类
 * 
 * @author Ericlin
 */
@Service
public class UserServiceImpl implements IUserService {

	@Autowired
	private UserDao userDao;

	@Override
	public int save(User user) {
		return userDao.insert(user);
	}

	@Override
	public boolean login(String username, String password) {
		User user = userDao.selectByUsernameAndPassward(username, password);
		if (user != null) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public User getUserById(int id) {
		return userDao.selectOne(id);
	}

	@Override
	public Integer updateUser(User user) {
		if (user.getId() != null && user.getId() > 0) {
			return userDao.update(user);
		}
		return userDao.insert(user);

	}

	@Override
	public Integer deleteUser(int id) {
		return userDao.delete(id);
	}

	@Override
	public List<User> getUsers(String username, int pageNo, int pageSize) {
		return userDao.select(username, pageNo, pageSize);
	}

	@Override
	public int count(String username) {
		return userDao.count(username);
	}

}
